home *** CD-ROM | disk | FTP | other *** search
- /*
- Copyright © 1991-1995 by TopSoft Inc. All rights reserved.
-
- You may distribute this file under the terms of the TopSoft
- Artistic License, accompanying this package.
-
- This file was developed by George (ty) Tempel in connection with TopSoft, Inc..
- See the Modification History for more details.
-
- Product
- About Box
-
- FILE
- ABObject.c
-
- NAME
- ABObject.c, part of the ABox project source code,
- responsible for handling the AboutBox drawn object stuff.
-
- DESCRIPTION
- This file contains defines for the about box modules.
-
- DEVELOPED BY
- George (ty) Tempel netromancr@aol.com
- All code in this file, and its associated header file was
- Created by George (ty) Tempel in connection with the TopSoft, Inc.
- "FilterTop" application development, except where noted.
-
- CARETAKER - George (ty) Tempel <netromancr@aol.com>
- Please consult this person for any changes or suggestions to this file.
-
- MODIFICATION HISTORY
-
- dd mmm yy - xxx - patchxx: description of patch
- 9 June 94 - ty - Initial Version Created
- 20-july-94 - ty - initial version released
- 12-aug-94 - ty - 1.0.8 -- added mix-in class ABUEnvQD
- for handling of quickdraw features
- 12-jan-95 - ty - 1.0.10 -- changed how the frames are drawn, inspired
- by the adorners of macapp--the frame will draw around
- the rect specified, not inside the rect. Thus,
- there will be no difference when viewing in 1bit vs n-bit
- 10-mar-95 - ty - 1.2 removed utility methods from here to ABUEnvQD
- since they were quickdraw related; inclusion of some
- new methods for handling DeviceLoop driven 3d frames
- of the object (pretty neat stuff!)
- 20-mar-95 - ty - 1.4 fixes to properly restore the clip region
- 21-mar-95 - ty - 1.5 fixes for ColorQD cautions on non-colorQD machines and
- better region handling for multiple devices
- 23-may-95 - ty - changes for compatibility with the CodeWarrior CW6
- release and the associated Universal Headers from Apple:
- most methods that returned references now have "Ref" at
- the end of their methods names to prevent possible collisions
- with datatypes and classes of the same name (older versions
- of the compiler didn't have a problem with this).
-
- */
-
- /*===========================================================================*/
-
- /*======= Segmentation directives ========*/
-
- #ifdef USE_MANUAL_SEGMENTATION
- #pragma segment ty
- #endif
-
- /*============ Header files ==============*/
-
- #include "ABObject.h"
-
- /*=============== Globals ================*/
-
- /*================ CODE ==================*/
-
- #ifndef topLeft
- #define topLeft(r) (((Point *)&(r))[0])
- #endif
-
- #ifndef botRight
- #define botRight(r) (((Point *)&(r))[1])
- #endif
-
-
- /*=============================== ABObject::ABObject ================================*/
- ABObject::ABObject(void)
- {
- mRefCon = 0;
- mVisibleObject = false;
-
- mOurWindow = NULL;
-
- mObjectRect.top = mObjectRect.bottom = mObjectRect.right = mObjectRect.left = 0;
-
- } // end ABObject
-
-
-
- /*=============================== ABObject::~ABObject ================================*/
- ABObject::~ABObject(void)
- {
- } // end ~ABObject
-
-
-
- /*=============================== ABObject::Draw ================================*/
- OSErr ABObject::Draw(WindowPtr window)
- {
- this->OurWindowRef() = window;
-
- // begin here...
- //
- // OVERRIDE THIS FUNCTION
- return this->DrawFrame();
- } // end Draw
-
-
-
- /*=============================== ABObject::Update ================================*/
- OSErr ABObject::Update(WindowPtr window)
- {
-
- // begin here...
- //
- // OVERRIDE THIS FUNCTION
-
- return this->Draw(window);
-
- } // end Update
-
-
-
-
- /*=============================== ABObject::Event ================================*/
- Boolean ABObject::Event(EventRecord* /*eventRec*/)
- {
- //#pragma unused (eventRec)
-
- // begin here...
- //
- // OVERRIDE THIS FUNCTION
-
- return false;
-
- } // end Event
-
-
-
- /*=============================== ABObject::Stop ================================*/
- OSErr ABObject::Stop(void)
- {
-
- // begin here...
- //
- // OVERRIDE THIS FUNCTION
-
- return noErr;
- } // end Stop
-
-
-
-
- /*=============================== ABObject::CheckFile ================================*/
- Boolean ABObject::CheckFile(FSSpecPtr /*fssptr*/)
- {
- //#pragma unused (fssptr)
-
- // begin here...
- //
- // OVERRIDE THIS FUNCTION
-
- return false;
- } // end CheckFile
-
-
-
- /*=============================== ABObject::InitializeObject ================================*/
- OSErr ABObject::InitializeObject(void)
- {
- // begin here...
- //
- // OVERRIDE THIS FUNCTION
-
- return noErr;
- } // end InitializeObject
-
-
-
- /*=============================== ABObject::Resize ================================*/
- OSErr ABObject::Resize(Rect const* /*field*/)
- {
- //#pragma unused (field)
-
- // begin here...
- //
- // OVERRIDE THIS FUNCTION
-
- return noErr;
- } // end Resize
-
-
-
-
-
-
- /*=============================== ABObject::GetProperty ================================*/
- OSErr ABObject::GetProperty(ABProperty prop,
- void *ptr,
- long *ptrSize)
- {
- OSErr error = noErr;
- long pSize;
-
- // begin here...
-
- if (!ptr)
- return kABPropertyNullStorage;
-
- switch (prop)
- {
- case kABObjectRefCon:
- *((long *)ptr) = mRefCon;
- pSize = kABObjectRefConSize;
- break;
- case kABObjectVisible:
- *((Boolean *)ptr) = this->VisibleObject();
- pSize = kABObjectVisibleSize;
- break;
- case kABObjectRect:
- (*(Rect *)ptr) = this->ObjectRect();
- pSize = kABObjectRectSize;
- break;
- default:
- error = kABObjectSuperProperty::GetProperty (prop, ptr, ptrSize);
- break;
- } // end switch block
-
- if (ptrSize && !error)
- *ptrSize = pSize;
- return error;
-
- } // end GetProperty
-
-
-
- /*=============================== ABObject::SetProperty ================================*/
- OSErr ABObject::SetProperty(ABProperty prop,
- void *ptr,
- long ptrSize)
- {
- OSErr error = noErr;
-
- // begin here...
-
- if (!ptr)
- return kABPropertyNullStorage;
-
- switch (prop)
- {
- case kABObjectRefCon:
- mRefCon = *((long *)ptr);
- break;
- case kABObjectVisible:
- this->VisibleObject() = *((Boolean *)ptr);
- break;
- case kABObjectRect:
- this->ObjectRect() = (*(Rect *)ptr);
- //::InsetRect(&this->ObjectRect(), 1, 1);
- break;
- default:
- error = kABObjectSuperProperty::SetProperty (prop, ptr, ptrSize);
- break;
- } // end switch block
-
- return error;
-
- } // end SetProperty
-
-
-
-
-
-
- /*=============================== ABObject::ScaleRectToFit ================================*/
- //
- // ScaleRectToFit will scale a rectangle to fit wholly within another, with an
- // optional reduction factor (expressed as 0.75 for a reduction to 75%, or 1.0
- // for normal).
- //
- // The function returns a pointer to the newly scaled rectangle in the parameter list,
- // and returns an OSErr for error processing.
- //
- //OSErr ABObject::ScaleRectToFit(Rect& item, Rect const *area, float factor)
- OSErr ABObject::ScaleRectToFit(Rect& item, const Rect& area, float factor)
- {
- OSErr error = noErr;
-
- float scale,
- xratio,
- yratio,
- extra = factor;
-
- short rectWidth,
- rectHeight,
- areaWidth,
- areaHeight;
-
-
- // begin...
-
- // begin here...
- //
- rectWidth = item.right - item.left;
- rectHeight = item.bottom - item.top;
-
- areaWidth = area.right - area.left;
- areaHeight = area.bottom - area.top;
-
- if ((rectWidth <= areaWidth) && (rectHeight <= areaHeight))
- {
- // the rect fits already...
- //
- } else {
- xratio = (float)(areaWidth * extra) / (float)rectWidth;
- yratio = (float)(areaHeight * extra) / (float)rectHeight;
-
- scale = (xratio < yratio) ? xratio : yratio;
-
- item.right = item.left + rectWidth * scale;
- item.bottom = item.top + rectHeight * scale;
-
- } // end if else block...
-
- return error;
-
- } // end of function ScaleRectToFit()
-
-
-
- /*=============================== ABObject::CanDraw3dBezel ==================================*/
- //
- // returns true if the pixel depth is sufficient for the bezel effect
- //
- Boolean
- ABObject::CanDraw3dBezel(short inDepth)
- {
- return inDepth >= kABminPixelDepthForBezel;
- }
-
-
-
-
-
- /*=============================== ABObject::EraseFrame ===============================*/
- //
- // this function will erase the beveled frame from around a rect area
- //
- // it will return an OSErr type to indicate error conditions.
- //
- //
- // is called by:
- //
- OSErr
- ABObject::EraseFrame (void) const
- {
- return this->EraseFrame(this->ObjectRect());
- } // end of function EraseFrame()
-
-
-
-
-
- /*=============================== ABObject::EraseFrame ===============================*/
- //
- // this function will erase the beveled frame from around a rect area
- //
- // it will return an OSErr type to indicate error conditions.
- //
- //
- // is called by:
- //
- OSErr
- ABObject::EraseFrame (Rect& rect)
- {
- OSErr error = noErr;
-
- // begin here...
-
- Rect theRect = rect;
-
- if (::EmptyRect(&theRect))
- return noErr;
-
- ::InsetRect (&theRect, -kABbezelWidth, -kABbezelWidth);
- theRect.right += 1;
- theRect.bottom += 1;
- ::EraseRect (&theRect);
- theRect.right -= 1;
- theRect.bottom -= 1;
- ::InsetRect (&theRect, kABbezelWidth, kABbezelWidth);
-
- return (error);
-
- } // end of function EraseFrame()
-
-
-
-
-
- /*=============================== ABObject::DrawFrame ===============================*/
- //
- // this function will draw a beveled frame around a rect area
- //
- OSErr
- ABObject::DrawFrame (void) const
- {
- return this->DrawFrame(this->ObjectRect());
- }
-
-
-
- /*=============================== ABObject::DrawFrame ===============================*/
- //
- // this function will draw a beveled frame around a rect area
- //
- // The function returns an OSErr to indicate error conditions.
- //
- OSErr
- ABObject::DrawFrame (Rect& inRect)
- {
- OSErr anError = noErr;
-
- // draw the frame via device loop calls...better in the long run if we can do this!
-
- RgnHandle theDrawRegion = ::NewRgn();
- DeviceLoopDrawingUPP theDrawUPP = NewDeviceLoopDrawingProc(ABObject::DeviceLoopDrawFrame);
- Rect theRect = inRect;
-
- if (theDrawUPP && theDrawRegion)
- {
- // construct a region from the given rect...
- ::RectRgn (theDrawRegion, &theRect);
-
- // now invoke the toolbox DeviceLoop
- ::DeviceLoop (theDrawRegion,
- theDrawUPP,
- (long)&theRect,
- allDevices);
- } else {
- // there was a problem, so try and draw the region best we can...
- ABUEnvQD hasColorQD;
- ABObject::DeviceLoopDrawFrame ((hasColorQD.HasColorQD() ? ABUEnvQD::GetPixelDepth(::GetGDevice()) : 1),
- allDevices,
- NULL,
- (long)&theRect);
-
- }
-
- if (theDrawRegion)
- {
- ::DisposeRgn(theDrawRegion);
- theDrawRegion = NULL;
- }
-
- if (theDrawUPP)
- {
- DisposeRoutineDescriptor(theDrawUPP);
- theDrawUPP = NULL;
- }
-
- return anError;
-
- }
-
-
- /*=============================== ABObject::DeviceLoopDrawFrame ===============================*/
- //
- // this function will draw a beveled frame around a rect area
- // following the suggestions put forth in Develop #15 for 3d effects
- // in user interfaces.
- //
- // It is _this_ method that does the actual frame drawing...all other DrawFrame
- // method eventually lead here via DeviceLoop...
- //
- pascal void
- ABObject::DeviceLoopDrawFrame (short inDepth, short inDeviceFlags, GDHandle inDevice, long inUserData)
- {
- OSErr error = noErr;
-
- Rect userAreaToDraw = *((Rect*)inUserData);
- RGBColor frameColor, prevColor;
-
- // begin here...
-
- if (::EmptyRect(&userAreaToDraw))
- return;
-
- // 1.1--expand the rect area so we can draw stuff
- ::InsetRect (&userAreaToDraw, -kABbezelWidth, -kABbezelWidth);
- Rect drawableIntersection = userAreaToDraw;
-
- // now determine if we should even bother drawing here just as yet...
- RgnHandle theClipRegion = ::NewRgn();
- if (theClipRegion)
- ::GetClip(theClipRegion);
-
- RgnHandle theDrawRegion = ::NewRgn();
-
- ABUEnvQD hasColorQD;
-
- Rect deviceBounds;
- Rect globalAreaToDraw = drawableIntersection;
-
- ::SetRect(&deviceBounds, 0, 0, 0, 0);
- if (inDevice)
- {
- deviceBounds = (*inDevice)->gdRect;
- } else {
- if (hasColorQD.HasColorQD())
- {
- GDHandle device = ::GetGDevice();
- if (device)
- deviceBounds = (*device)->gdRect;
- }
- }
-
- ::LocalToGlobal(&topLeft(globalAreaToDraw));
- ::LocalToGlobal(&botRight(globalAreaToDraw));
-
- if (::SectRect(&deviceBounds, &globalAreaToDraw, &drawableIntersection))
- {
- // there is an intersection, so set things up...
- if (theDrawRegion && theClipRegion)
- {
- // convert back to local coords...
- ::GlobalToLocal(&topLeft(drawableIntersection));
- ::GlobalToLocal(&botRight(drawableIntersection));
-
- // start setting up the drawing regions and clip regions now...
- ::RectRgn (theDrawRegion, &drawableIntersection);
-
- // set theDrawRegion to be the clipped area, just to
- // be nice
-
- if (::EmptyRgn(theClipRegion) == false)
- ::SectRgn(theDrawRegion, theClipRegion, theDrawRegion);
-
- // now clip to the visRgn too...
- ::SectRgn(theDrawRegion, qd.thePort->visRgn, theDrawRegion);
-
- // now set the _new_ clip region...
- ::SetClip (theDrawRegion);
- }
- }
-
- // see if there really was an intersection to draw into...
- if (theDrawRegion && theClipRegion && (::EmptyRgn(theDrawRegion) == false))
- {
- // we should always get here, but just to make certain...
-
- if (ABObject::CanDraw3dBezel(inDepth) && inDevice && hasColorQD.HasColorQD())
- {
- // when called on a system without ColorQuickdraw, the inDevice parameter is
- // set to NULL...
-
- // now do the draw...
- ::GetForeColor (&prevColor);
-
- // draw the left & top first...
- // set the color
-
- frameColor.blue = frameColor.red = frameColor.green = k3D_lineMedLightGrey;
- if (hasColorQD.HasColorQD())
- ::RGBForeColor (&frameColor);
-
- ::MoveTo (userAreaToDraw.left, userAreaToDraw.bottom);
- ::LineTo (userAreaToDraw.left, userAreaToDraw.top);
- ::LineTo (userAreaToDraw.right, userAreaToDraw.top);
-
- // draw the bottom and right...
- // set the bottom/right colors
- frameColor.blue = frameColor.red = frameColor.green = k3D_lineWhite;
- if (hasColorQD.HasColorQD())
- ::RGBForeColor (&frameColor);
-
- ::InsetRgn (theDrawRegion, -kABbezelWidth, -kABbezelWidth);
- ::SetClip (theDrawRegion);
- ::MoveTo (userAreaToDraw.left, userAreaToDraw.bottom);
- ::LineTo (userAreaToDraw.right, userAreaToDraw.bottom);
- ::LineTo (userAreaToDraw.right, userAreaToDraw.top);
-
- if (hasColorQD.HasColorQD())
- ::RGBForeColor(&prevColor);
-
- } else {
- ::FrameRect (&userAreaToDraw);
-
- } // end if else block...
-
- }
-
- if (theClipRegion)
- {
- // restore the clip region
- ::SetClip (theClipRegion);
- ::DisposeRgn(theClipRegion);
- theClipRegion = NULL;
- }
-
- if (theDrawRegion)
- {
- ::DisposeRgn(theDrawRegion);
- theDrawRegion = NULL;
- }
-
- return;
-
- } // end of function DrawFrame()
-
-